<?php


namespace App\Transformers\Statistics;


use App\Models\ProductLog;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class ProductLogTransformer extends TransformerAbstract
{
    protected  $availableIncludes = ['product','user'];

    public function transform(ProductLog $data)
    {
        return [
            'id' => $data->id,
            'type' => $data->type ?? '',
            'type_text' => $data->typeTypeEnum[$data->type] ?? '',
            'product_id' => $data->product_id ?? '',
            'user_id' => $data->user_id ?? '',
            'visit_num' => $data->visit_num ?? '',
            'visitor_num' => $data->visitor_num ?? '',
            'cart_num' => $data->cart_num ?? '',
            'order_num' => $data->order_num ?? '',
            'pay_num' => $data->pay_num ?? '',
            'pay_price' => $data->pay_price ?? '',
            'cost_price' => $data->cost_price ?? '',
            'pay_user_id' => $data->pay_user_id ?? '',
            'refund_num' => $data->refund_num ?? '',
            'refund_price' => $data->refund_price ?? '',
            'collect_num' => $data->collect_num ?? '',
            'margin' => $data->margin ?? '',
            'payment' => $data->payment ?? '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'product' => $data->product ?? '',
        ];
    }
        /**
         * 包含的商品
         */
        public function includeproduct(ProductLog $productLog){
            return $this->item($productLog->product,new ProductTransformer());
        }

        public function includeuser(ProductLog $productLog){
            return $this->item($productLog->user,new UserTransformer());
        }

}
